package com.blog.controller;

import com.alibaba.fastjson.JSONObject;
import com.blog.pojo.Tag;
import com.blog.service.TagService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Copyright (C), 2022
 * Author: 苏大大
 * Date: 2022-04-23 16:28
 * FileName: BlogTagController
 * Description: 博客标签控制层
 */
@RestController
@RequestMapping("blog/tag")
@Slf4j
public class BlogTagController {

    @Resource
    private TagService blogTagService;

    @GetMapping("/queryAll")
    public String queryAll(){
        JSONObject object=new JSONObject();
        List<Tag> list= blogTagService.queryTagAll();
        object.put("tagList",list);
        return object.toJSONString();
    }

    @GetMapping("/queryAll/{pageNumber}/{pageSize}")
    public String queryAll( @Param("开始页数") @PathVariable("pageNumber") Integer pageNumber,
                            @Param("总页数") @PathVariable("pageSize") Integer pageSize,
                            @Param("查询条件") @RequestParam(defaultValue = "null") @PathVariable("queryString") String queryString){
        JSONObject object=new JSONObject();
        PageInfo<Tag> PageInfo = blogTagService.queryTagPageAll(pageNumber,pageSize,queryString);
        object.put("tagPageList",PageInfo.getList());
        object.put("pages",PageInfo.getPages());
        object.put("total",PageInfo.getTotal());
        log.info("总页数为====>>>>>>>>>>>>>>>>>>>>{}",PageInfo.getPages());
        log.info("总条数为====>>>>>>>>>>>>>>>>>>>>{}",PageInfo.getTotal());
        object.put("flag",PageInfo.getList()!=null);
        return object.toJSONString();
    }

}
